package com.financing.wap.dao.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.financing.wap.dto.*;

import org.springframework.stereotype.Repository;

import com.financing.wap.common.Pager;
import com.financing.wap.common.SqlName;
import com.financing.wap.dao.IOrderDao;
import com.financing.wap.dao.wherecondition.WhereCondition;
import com.financing.wap.vo.OrderCountVO;
import com.financing.wap.vo.OrderDoneCountDto;
import com.financing.wap.vo.OrderResVO;
import com.financing.wap.vo.OrderVO;

/**
 * @author Mars
 * @createDate 2014年8月22日
 */
@Repository("orderDao")
@SuppressWarnings(value={"unchecked", "deprecation"})
public class OrderDaoImpl extends BaseDaoImpl<OrderDTO, Integer>  implements IOrderDao{

	private static final String BigDecimal = null;


	@Override
	public List<OrderDTO> getOrderList(OrderVO where) { 
		List<OrderDTO> queryForList = this.sqlMapClientTemplate.queryForList(SqlName.ORDER_QUERY_LIST, where);
		return queryForList;
	}
	

	@Override
	public Integer getOrderListCount(OrderVO where) {
		Integer count = (Integer)this.sqlMapClientTemplate.queryForObject(SqlName.ORDER_QUERY_LIST_COUNT, where);
		return count;
	}

	@Override
	public OrderDTO getOrder(String id) {
		OrderDTO o = (OrderDTO) this.sqlMapClientTemplate.queryForObject(SqlName.ORDER_QUERY, id);
		return o;
	}

	@Override
	public Class<OrderDTO> getEntityClass() {

		return null;
	}

	@Override
	public void changeOrderStatus(OrderDTO order) {
		this.sqlMapClientTemplate.update(SqlName.ORDER_CHANGE_STATUS, order);
		return;
	}

	@Override
	public String applyPreOrder(OrderDTO order) {
		order.setId((String)this.sqlMapClientTemplate.queryForObject(SqlName.queryUUID));
		this.sqlMapClientTemplate.insert(SqlName.APPLY_PRE, order);
		return order.getId();
	}


	@Override
	public List<OrderDTO> getCorpOrderList(OrderVO where) {
		List<OrderDTO> queryForList = this.sqlMapClientTemplate.queryForList(SqlName.CORP_ORDER_QUERY_LIST, where);
		return queryForList;
	}


	@Override
	public Integer getCorpOrderListCount(OrderVO where) {
		Integer count = (Integer)this.sqlMapClientTemplate.queryForObject(SqlName.CORP_ORDER_QUERY_LIST_COUNT, where);
		return count;
	}


	@Override
	public Integer insertOrderFlow(OrderFlowDTO dto) {
		 
		return (Integer)this.sqlMapClientTemplate.insert(SqlName.ORDER_FLOW_INSERT,dto);
	}


	@Override
	public List<OrderDTO> queryTOPOrder(Integer limit) {
		return this.sqlMapClientTemplate.queryForList(SqlName.QUERY_TOP_ORDER,limit);
	}


	@Override
	public Integer countDealOrder(String faId) {
		return (Integer) this.sqlMapClientTemplate.queryForObject(SqlName.COUNT_DEAL_ORDER,faId);
	}


	@Override
	public BigDecimal getOrderAmountCount(Map<String, Object> map) {
		return (BigDecimal) this.sqlMapClientTemplate.queryForObject(SqlName.getOrderAmountCount,map);
	}


	@Override
	public List<String> countOrderManagerForUserId(String faId) {
		return (List<String>) this.sqlMapClientTemplate.queryForList(SqlName.countOrderManagerForUserId,faId);
	}

	@Override
	public List<String> queryOrderManagerUserBySource(String sourceCode){
		return this.sqlMapClientTemplate.queryForList(SqlName.queryOrderManagerUserBySource, sourceCode);
	}


	@Override
	public List<Integer> getSonFaidList(String corpId) {
		return this.sqlMapClientTemplate.queryForList(SqlName.querySonFaidList, corpId);
	}


	@Override
	public Integer getBiddingProjectListCount(OrderVO orderVo) {
		Integer count = (Integer)this.sqlMapClientTemplate.queryForObject(SqlName.queryMyYouDanProjectListCount, orderVo);
		return count;
	}


	@Override
	public List<YouDanOrderByProjectDTO> getBiddingProjectList(OrderVO where) {
		List<YouDanOrderByProjectDTO> queryForList = this.sqlMapClientTemplate.queryForList(SqlName.queryMyYouDanProjectList, where);
		return queryForList;
	}


	@Override
	public BigDecimal getYouDanReservedAmountByProjectId(Map<String, Object> tempMap) {
		return (BigDecimal) this.sqlMapClientTemplate.queryForObject(SqlName.getYouDanReservedAmountByProjectId, tempMap);
	}

	@Override
	public BigDecimal getYouDanConfirmedAmountByProjectId(Map<String, Object> tempMap) {
		return (BigDecimal) this.sqlMapClientTemplate.queryForObject(SqlName.getYouDanConfirmedAmountByProjectId, tempMap);
	}


	@Override
	public BigDecimal getMyYouDanOrderAllRebateAmount(OrderVO orderVo) {
		return (BigDecimal) this.sqlMapClientTemplate.queryForObject(SqlName.getMyYouDanOrderAllRebateAmount, orderVo);
	}


	@Override
	public BigDecimal getPayingCommission(Map<String, Object> tempMap) {
		return (BigDecimal) this.sqlMapClientTemplate.queryForObject(SqlName.getPayingCommission, tempMap);
	}


	@Override
	public BigDecimal getPayedCommission(Map<String, Object> tempMap) {
		return (BigDecimal) this.sqlMapClientTemplate.queryForObject(SqlName.getPayedCommission, tempMap);
	}

	@Override
	public Integer getYouDanOrderListCount(OrderVO orderVo) {
		Integer count = (Integer)this.sqlMapClientTemplate.queryForObject(SqlName.getYouDanOrderListCount, orderVo);
		return count;
	}

	@Override
	public List<OrderDTO> getYouDanOrderList(OrderVO orderVo) {
		List<OrderDTO> queryForList = this.sqlMapClientTemplate.queryForList(SqlName.getYouDanOrderList, orderVo);
		return queryForList;
	}


	@Override
	public OrderDTO getYouDanOrderDetail(OrderVO orderVo) {
		return (OrderDTO) this.sqlMapClientTemplate.queryForObject(SqlName.getYouDanOrderDetail, orderVo);
	}


	@Override
	public YouDanOrderByProjectDTO getYouDanCommissionByProduct(Map<String, Object> tempMap) {
		return (YouDanOrderByProjectDTO) this.sqlMapClientTemplate.queryForObject(SqlName.getYouDanCommissionByProduct, tempMap);
	}


	@Override
	public ProductDTO getProduct(Map<String, Object> tempMap) {
		return (ProductDTO) this.sqlMapClientTemplate.queryForObject(SqlName.getProduct, tempMap);
	}


	@Override
	public HashMap<String, Object> getYouDanAmountByOrder(OrderDTO orderDto) {
		return (HashMap<String, Object>) this.sqlMapClientTemplate.queryForObject(SqlName.getYouDanAmountByOrder, orderDto);
	}


	@Override
	public List<YouDanCommissionDTO> myBiddingProjectCommission(Map<String, Object> tempMap) {
		return this.sqlMapClientTemplate.queryForList(SqlName.myBiddingProjectCommission, tempMap);
	}


	@Override
	public BigDecimal getMyOrderFrontRebateAmount(OrderVO orderVo) {
		BigDecimal result = (BigDecimal) this.sqlMapClientTemplate.queryForObject(SqlName.getMyOrderFrontRebateAmount, orderVo);
		if(null == result){
			return new BigDecimal(0);
		}else{
			return result;
		}
	}
	
	@Override
	public BigDecimal getMyOrderBackRebateAmount(OrderVO orderVo) {
		BigDecimal result = (BigDecimal) this.sqlMapClientTemplate.queryForObject(SqlName.getMyOrderBackRebateAmount, orderVo);
		if(null == result){
			return new BigDecimal(0);
		}else{
			return result;
		}
	}


	@Override
	public BigDecimal getMyAllOrderRebateAmount(OrderVO orderVo) {
		BigDecimal result = (BigDecimal) this.sqlMapClientTemplate.queryForObject(SqlName.getMyAllOrderRebateAmount, orderVo);
		if(null == result){
			return new BigDecimal(0);
		}else{
			return result;
		}
	}

	@Override
	public BigDecimal orderCommissionCount(String faId) {
		return (BigDecimal)this.sqlMapClientTemplate.queryForObject("order.countCommissionOrder", faId);
	}

	@Override
	public BigDecimal queryOrderCostCount(FpOrderCostDTO orderCost) {
		return (BigDecimal)this.sqlMapClientTemplate.queryForObject("order.queryOrderCostCount", orderCost);
	}


	@Override
	public List<OrderCountVO> orderListCount(OrderDTO orderDto) {
		return this.sqlMapClientTemplate.queryForList(SqlName.ORDER_LIST_COUNT, orderDto);
	}


	@Override
	public List<OrderCountVO> orderTimesCount(OrderDTO orderDto) {
		return this.sqlMapClientTemplate.queryForList(SqlName.ORDER_TIMES_COUNT, orderDto);
	}
	
	@Override
	public List<OrderCountVO> orderTimesCountDone(OrderDTO orderDto) {
		return this.sqlMapClientTemplate.queryForList(SqlName.ORDER_TIMES_COUNT_DONE, orderDto);
	}
	
	@Override
	public List<OrderCountVO> orderCountByTimeAndOrg(OrderDTO orderDto, FpManagerOrder fpman) {
		Map<String, Object> parames = new HashMap<String, Object>();
		parames.put("orderparame", orderDto);
		parames.put("fpmanparame", fpman);
		return this.sqlMapClientTemplate.queryForList(SqlName.ORDER_COUNT_BYTIMESANDORG, parames);
	}
	
	@Override
	public List<String> queryOrderXaxisDatas(OrderDTO orderDto, FpManagerOrder fpman) {
		Map<String, Object> parames = new HashMap<String, Object>();
		parames.put("orderparame", orderDto);
		parames.put("fpmanparame", fpman);
		return this.sqlMapClientTemplate.queryForList(SqlName.QUERY_ORDER_XAXIS, parames);
	}
	
	@Override
	public OrderDoneCountDto queryCountOrderDone(OrderDTO orderDto, FpManagerOrder fpman, WhereCondition wc) {
		Map<String, Object> parames = new HashMap<String, Object>();
		parames.put("orderparame", orderDto);
		parames.put("fpmanparame", fpman);
		parames.put("wc", wc);
		return (OrderDoneCountDto) this.sqlMapClientTemplate.queryForObject(SqlName.QUERY_COUNT_ORDERDONE, parames);
	}
	
	@Override
	public List<OrderResVO> queryOrderDoneByWherecondition(OrderDTO orderDto, FpManagerOrder fpman, WhereCondition wc) {
		Map<String, Object> parames = new HashMap<String, Object>();
		parames.put("orderparame", orderDto);
		parames.put("fpmanparame", fpman);
		parames.put("wc", wc);
		return this.sqlMapClientTemplate.queryForList(SqlName.QUERY_ORDERDONE_BY_WHERECONDITION, parames);
	}
}
